﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace LetLord.Models
{
    public enum PropertyType { Apartment, TownHouse, Bungalow, Cottage, Detached, SemiDetached, Terrace, Mews }

    [Table("ResidentialProperty")]
    public class ResidentialProperty
    {
        public ResidentialProperty()
        {
            this.PropertyPhotos = new List<PropertyPhoto>();
            this.Viewings = new List<Viewing>();
        }

        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int ResidentialPropertyId { get; set; }
        public PropertyType PropertyType { get; set; }
        [Display(Name = "Size (Sq. Mtrs.)")]
        public string SizeSquareMeters { get; set; }
        [Display(Name = "Bedrooms<br/>")]
        public string NumberOfBedrooms { get; set; }
        [Display(Name = "Bathrooms<br/>")]
        public string NumberOfBathrooms { get; set; }
        [Display(Name = "Reception rooms")]
        public string NumberOfReceptionRooms { get; set; }
        public string Description { get; set; }
        [Display(Name = "Back<br/>garden")]
        public bool HasBackGarden { get; set; }
        [Display(Name = "Front<br/>garden")]
        public bool HasFrontGarden { get; set; }
        [Display(Name = "Disabled access")]
        public bool IsDisabledFriendly { get; set; }
        [Display(Name = "Secure parking")]
        public bool HasSecureParking { get; set; }
        public DateTime DateAdded { get; set; }
        [Display(Name = "Monthly rate")]
        public decimal MonthlyRate { get; set; }

        public virtual string PropertyTypeString
        {
            get { return PropertyType.ToString(); }
            set
            {
                PropertyType newValue;
                if (Enum.TryParse(value, out newValue))
                { PropertyType = newValue; }
            }
        }



        // A ResidentialProperty can have many PropertyPhotos
        //[ForeignKey("ImageId")]
        public virtual ICollection<PropertyPhoto> PropertyPhotos { get; set; }

        // A ResidentialProperty can have many Viewings
        //[ForeignKey("ViewingId")]
        public virtual ICollection<Viewing> Viewings { get; set; }

        // A ResidentialProperty has 1 Landlord
        public virtual int UserId { get; set; }
        [ForeignKey("UserId")]
        public virtual Landlord Landlord { get; set; } 

        // A ResidentialProperty has 1 address
        public virtual int AddressId { get; set; }
        [ForeignKey("AddressId")]
        public virtual Address Address { get; set; }
    }
}